package com.dhnsoft.代码随想录.栈与队列;

import java.util.Stack;

/**
 * ClassName: d01_232_用栈实现队列
 * Package: com.dhnsoft.代码随想录.栈与队列
 * Description:
 *
 * @Author dhn
 * @Create 2024/3/25 12:35
 * @Version 1.0
 */
public class d01_232_用栈实现队列 {
}

class MyQueue {
    Stack<Integer> stackIn;
    Stack<Integer> stackOut;

    public MyQueue() {
        stackIn = new Stack<>();
        stackOut = new Stack<>();
    }

    public void push(int x) {
        stackIn.push(x);
    }

    public int pop() {
        dumpstackIn();
        return stackOut.pop();
    }

    public int peek() {
        dumpstackIn();
        return stackOut.peek();
    }

    public boolean empty() {
        return stackOut.isEmpty()&&stackIn.isEmpty();
    }

    public void dumpstackIn(){
        if(!stackOut.isEmpty()){
            return;
        }
        while (!stackIn.isEmpty()){
            stackOut.push(stackIn.pop());
        }
    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * boolean param_4 = obj.empty();
 */